package com.share.shareplatform.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Goods {

    public final static String[] fields={"id","shopId","brandId","typeId","name","place","number","price","deal","introduce"};

    private Long id;
    private Long shopId;

    private Long brandId;
    private Long typeId;//商品类型

    @NotBlank(message = "名称不能为空")
    @Length(max = 20 ,message = "名称太长")
    private String name;

    @NotBlank(message = "出产地不能为空")
    @Length(max = 100,message = "出产地名太长")
    private String place;//生产地

    private Integer number;//剩余数量

    private Double price;//价格

    private Double rentPrice;//租赁价格

    private Integer deal;//交易次数

    @Length(max = 100,message = "介绍太长")
    private String introduce;//介绍

    private String image;//图片

    private String size;

    private String donate;//是否是租赁物品

    private Type type;

    private Brand brand;

    public static void setInit(Goods goods){
        goods.setDeal(0);
    }

    public static void setUnAlter(Goods goods){
        goods.setDeal(null);
    }

    //更新
    public static void update(Goods oldGoods,Goods newGoods){
        if(newGoods.getBrandId()!=null){
            oldGoods.setBrandId(newGoods.getBrandId());
        }
        if(newGoods.getTypeId()!=null){
            oldGoods.setTypeId(newGoods.getTypeId());
        }
        if(newGoods.getName()!=null){
            oldGoods.setName(newGoods.getName());
        }
        if(newGoods.getPlace()!=null){
            oldGoods.setPlace(newGoods.getPlace());
        }
        if(newGoods.getNumber()!=null){
            oldGoods.setNumber(newGoods.getNumber());
        }
        if(newGoods.getPrice()!=null){
            oldGoods.setPrice(newGoods.getPrice());
        }
        if(newGoods.getIntroduce()!=null){
            oldGoods.setIntroduce(newGoods.getIntroduce());
        }
        if(newGoods.getRentPrice()!=null){
            oldGoods.setRentPrice(newGoods.getRentPrice());
        }
    }
}





















































































































































































































































































































































